1 module hip.api.filesystem.hipfs; 2 3 ///Less dependencies 4 enum 5 { 6 /// Offset is relative to the beginning 7 SEEK_SET, 8 /// Offset is relative to the current position 9 SEEK_CUR, 10 /// Offset is relative to the end 11 SEEK_END 12 } 13 14 enum FileMode 15 { 16 READ, 17 WRITE, 18 APPEND, 19 READ_WRITE, 20 READ_APPEND 21 } 22 23 ///Unused yet, but planned 24 interface IHipDirectoryItf 25 { 26 bool open(); 27 bool close(); 28 string[] getFileNames(); 29 size_t count(); 30 int opApply(scope int delegate(in string fileName) dg); 31 } 32 33 interface IHipFileItf 34 { 35 bool open(string path, FileMode mode); 36 int read(void* buffer, ulong count); 37 ///Whence is the same from stdio 38 int seek(long count, int whence); 39 ulong getSize(); 40 void close(); 41 } 42 interface IHipFSPromise 43 { 44 IHipFSPromise addOnSuccess(void delegate(in ubyte[] data) onSuccess); 45 IHipFSPromise addOnError(void delegate(string error) onError); 46 bool resolved() const; 47 48 } 49 50 interface IHipFileSystemInteraction 51 { 52 protected final const(wchar*) cachedWStringz(wstring path) 53 { 54 __gshared wchar[] cache; 55 if(path.length > cache.length) 56 cache.length = path.length + 1; 57 cache[0..path.length] = path[]; 58 cache[path.length] = '\0'; 59 60 return cache.ptr; 61 } 62 63 protected final const(char*) cachedStringz(string path) 64 { 65 __gshared char[] cache; 66 if(path.length > cache.length) 67 cache.length = path.length + 1; 68 cache[0..path.length] = path[]; 69 cache[path.length] = '\0'; 70 71 return cache.ptr; 72 } 73 74 /** 75 * onSuccess: Maybe be executed before the function returns (on sync platforms). 76 * 77 * onError: Error is reserved for when the file exists but can't be read. 78 Not being able to read because it doesn't exists is not an error. 79 * 80 * 81 * Returns: 82 * - Sync Platforms: File does not exists, can't read. 83 * - Async platforms: File does not exists 84 */ 85 bool read(string path, void delegate(ubyte[] data) onSuccess, void delegate(string err = "Corrupted File") onError); 86 bool write(string path, void[] data); 87 bool exists(string path); 88 bool remove(string path); 89 90 bool isDir(string path); 91 final bool isFile(string path){return !isDir(path);} 92 }